<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="com.yaodian100.crm.cs.entity.CommonQuestionType" %>
<%@taglib uri="/WEB-INF/tld/pageutil.tld" prefix="pu"%>
<%@taglib uri="/WEB-INF/tld/pageable.tld" prefix="pageable"%>
<%@taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c-rt"%>
<%@taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt-rt"%>

<%!
void buildTree(Object[] objs, StringBuffer sb, int count, ServletContext application){
    count++;
    if(count>10)return;
    if(objs!=null && objs.length>0){
		sb.append("<ul>"); 
	    for(Object obj:objs){
		CommonQuestionType cqt=(CommonQuestionType)obj;
		String rel="processNode";
		if(cqt.getShowOnQAA()==null || !cqt.getShowOnQAA())rel="processNodeNoneShow";
			sb.append("<li id=\""+cqt.getId()+"\" rel=\""+rel+"\"><a href=\"#\" onclick=\"doAR('"+application.getContextPath()+"/cs/page.do?iamlazy=questionClassDetail&id="+cqt.getId()+"&parentId="+cqt.getParent().getId()+"', 'rightSide')\"><ins>&nbsp;</ins>"+cqt.getName()+"</a>"); 
			if(cqt.getChilds()!=null && cqt.getChilds().size()>0){
			    buildTree(cqt.getChilds().toArray(), sb, count, application);
			}
			sb.append("</li>");
	    }
	    sb.append("</ul>");
    }
}
%>
<c-rt:set var="hql">
from CommonQuestionType where parent=null order by id asc
</c-rt:set>
<c-rt:set var="cqtMains" value="${pu:queryByHql(hql, null, null)}"/>

		
			<script type="text/javascript" class="source"> 
	$(function () { 
		
		$("#leftSide").tree(
			{
				rules : {
				// only nodes of type root can be top level nodes
				valid_children : [ "root" ]
				},
				types : {
				// all node types inherit the "default" node type
				"default" : {
					deletable : false,
					renameable : false,
					draggable: false
				},
				"root" : {
					draggable : false,
					valid_children : [ "processNode", "processNodeNoneShow" ],
					icon : { 
						image : "<%=application.getContextPath() %>/images/FAMFAMFAM/application_form_add.png"
					}
				},
				"processNode" : {
					valid_children : [ "processNode", "processNodeNoneShow" ],
					icon : { 
						image : "<%=application.getContextPath() %>/images/FAMFAMFAM/application.png"
					}
				},
				"processNodeNoneShow" : {
					valid_children : [ "processNode", "processNodeNoneShow" ],
					icon : { 
						image : "<%=application.getContextPath() %>/images/FAMFAMFAM/application_delete.png"
					}
				}
				}
			}
		);
		var focused='${param.focused}';
		if(focused!=''){
			$.tree.focused().open_branch("#theFlowTree");	
			$.tree.focused().open_all("#theFlowTree");
			$.tree.focused().open_branch("#"+focused);
			$.tree.focused().open_all("#"+focused);
		}
		$('#theTree').show();
	});
	
	</script> 
		<ul id="theTree" style="display:none"> 
			<li id="theFlowTree" rel="root" class="open"><a href="#" onclick="doAR('<%=application.getContextPath() %>/cs/page.do?iamlazy=questionClassDetail', 'rightSide')">问题分类管理</a>
			<c-rt:if test="${!empty cqtMains}"> 
				<ul> 
					<c-rt:forEach items="${cqtMains }" var="cqtMain">
					<c-rt:if test="${cqtMain.showOnQAA}">
						<c-rt:set var="rel" value="processNode"/>
					</c-rt:if>
					<c-rt:if test="${empty cqtMain.showOnQAA || !cqtMain.showOnQAA}">
						<c-rt:set var="rel" value="processNodeNoneShow"/>
					</c-rt:if>
					<li id="${cqtMain.name }" rel="${rel }"><a href="#" onclick="doAR('<%=application.getContextPath() %>/cs/page.do?iamlazy=questionClassDetail&id=${cqtMain.id }&parentId=${cqtMain.parent.id }', 'rightSide')"><ins>&nbsp;</ins>${empty cqtMain.description?cqtMain.name:cqtMain.description }</a>
					<c-rt:if test="${!empty cqtMain.childs}">
						<%
						CommonQuestionType cqt=(CommonQuestionType)pageContext.getAttribute("cqtMain");
						StringBuffer sb=new StringBuffer("");
						buildTree(cqt.getChilds().toArray(), sb, 0, application);
						out.print(sb.toString());
						
						%>
					</c-rt:if>
					</li> 
					<%
					pageContext.setAttribute("params", null);
					request.setAttribute("paras", null);
					%>
					</c-rt:forEach>
				</ul>
				</c-rt:if> 
			</li> 
			
		</ul> 

	